//
//  kata_OKInfoViewController.m
//  CityStar
//
//  Created by wangjia on 14-7-13.
//  Copyright (c) 2014年 kata. All rights reserved.
//

#import "kata_OKInfoViewController.h"
#import "HTDefine.h"
#import "Define.h"
#import "HttpRequestManager.h"
#import "KInterFace.h"
#import "SVProgressHUD.h"

@interface kata_OKInfoViewController ()

@property (nonatomic, strong)NSString *strName;
@property (nonatomic, strong)NSString *strPrice;
@property (nonatomic, strong)NSString *strUUID;
@end

@implementation kata_OKInfoViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(void)setMessage:(NSDictionary *)dic
{
    DLog(@"%@",dic);
    self.strName = dic[@"name"];
    self.strPrice = dic[@"price"];
    self.strUUID = dic[@"uuid"];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"预订车位";
//    [self.btnCancel setGrayStyle];

    NSString *strPrice = @"6元/小时";
    NSString *strTime = @"请在20分钟内前往";
    
//    [self.lblPrice setText:strPrice afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString  *(NSMutableAttributedString *mutableAttributedString) {
//        NSRange range = [strPrice rangeOfString:@"6"];
//        [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[[UIColor redColor] CGColor] range:range];
//        return mutableAttributedString;
//    }];
//    
//    [self.lblTime setText:strTime afterInheritingLabelAttributesAndConfiguringWithBlock:^ NSMutableAttributedString  *(NSMutableAttributedString *mutableAttributedString) {
//        NSRange range = [strTime rangeOfString:@"20"];
//        [mutableAttributedString addAttribute:(NSString *)kCTForegroundColorAttributeName value:(id)[[UIColor redColor] CGColor] range:range];
//        return mutableAttributedString;
//    }];
    
    UIButton * regBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
    regBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [regBtn setTitleColor:rgba(133, 133, 133, 1) forState:UIControlStateHighlighted];
    [regBtn setImage:[UIImage imageNamed:@"map"] forState:UIControlStateNormal];
    [regBtn setImage:[UIImage imageNamed:@"map_touch"] forState:UIControlStateHighlighted];
    [regBtn addTarget:self action:@selector(mapAction) forControlEvents:UIControlEventTouchUpInside];
	UIBarButtonItem * iHaveNewsBtnItem = [[UIBarButtonItem alloc]initWithCustomView:regBtn];
	self.navigationItem.rightBarButtonItem = iHaveNewsBtnItem;
    
    
    // Do any additional setup after loading the view.
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 90, 30)];
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setFrame:CGRectMake(-30, 0, 90, 30)];
    [leftButton setTitle:@"返回" forState:UIControlStateNormal];
    leftButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [leftButton setTitleColor:[UIColor colorWithWhite:0.200 alpha:1.000] forState:UIControlStateNormal];
    [leftButton setTitleColor:[UIColor colorWithRed:0.991 green:0.532 blue:0.303 alpha:1.000] forState:UIControlStateHighlighted];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [leftButton setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [leftButton setImage:[UIImage imageNamed:@"back_touch"] forState:UIControlStateHighlighted];
    
    [view addSubview:leftButton];
    
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:view];
    self.navigationItem.leftBarButtonItem = barButtonItem;
    
    
}

-(void)viewWillAppear:(BOOL)animated
{
    self.labelName.text = self.strName;
    self.lblPrice.text = self.strPrice;
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)mapAction{
    [self performSegueWithIdentifier:@"segMap" sender:nil];
}

- (IBAction)connectAction:(id)sender {
    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"是否联系管理员" message:@"182-2906-2533" delegate:self cancelButtonTitle:nil otherButtonTitles:@"拨号",@"取消", nil];
    av.tag = 1;
    [av show];
}

- (IBAction)cancelAction:(id)sender {
    UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"是否取消订单" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"确认",@"取消", nil];
    av.tag = 2;
    [av show];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex{
    if (alertView.tag == 1) {
        if (buttonIndex == 0) {
            NSString *phone = @"182-2906-2533";
            NSString *telUrl = [NSString stringWithFormat:@"telprompt:%@",phone];
            NSURL *url = [[NSURL alloc] initWithString:telUrl];
            [[UIApplication sharedApplication] openURL:url];
        }
    }else if(alertView.tag == 2){
        if (buttonIndex == 0) {
            [HttpRequestManager putMethod:KinterFace_DriverCancel parameters:@{@"uuid":self.strUUID} completedMainBlock:^(BOOL success, id response, NSString *errMsg) {
                if (success) {
                    [SVProgressHUD showSuccessWithStatus:@"取消订单成功"];
                    [self.navigationController popViewControllerAnimated:YES];
                }
            }];
        }
    }
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
@end
